#!/bin/sh
#****************************************************************#
# ScriptName: shellScript/mysql_cgroup_2to1.sh
# Author: 
# Create Date: 2012-07-31
# Modify Author: 
# Modify Date: 2012-07-31
# Function: 
#***************************************************************#
#set -x

# echo red text of $1
echo_red()
{
        # echo a message with red color
        echo -e "\e[1;31m$@\e[m"
        return 0
}

# echo green text of $1
echo_green()
{
        echo -e "\e[1;32m$@\e[m"
        return 0
}

# echo yellow text of $1
echo_yellow()
{
        echo -e "\e[1;33m$@\e[m"
        return 0
}

# echo blue text of $1
echo_blue()
{
        echo -e "\e[1;34m$@\e[m"
        return 0
}

# echo purple text of $1 紫色
echo_purple()
{
        echo -e "\e[1;35m$@\e[m"
        return 0
}

# echo viridity text of $1 青绿
echo_viridity()
{
        echo -e "\e[1;36m$@\e[m"
        return 0
}

# echo lightgrey text of $1 浅灰
echo_lightgrey()
{
        echo -e "\e[1;37m$@\e[m"
        return 0
}

#### stop dbagent ####
dbagent disable

#### stop mysql ####
echo_blue "\n\n#### stop mysql ####"
## stop mysql 1 ##
echo_blue "## stop mysql 1 ##"
su - mysql -c 'export LANG=c; /u01/mysql/bin/mysqladmin --defaults-file=/u01/mysql/my.cnf -uroot shutdown'
for i in `seq 2 4`; do 
	echo_blue "## stop mysql $i ##"
	su - mysql -c "export LANG=c; /u01/mysql/bin/mysqladmin --defaults-file=/u01/mysql$i/my.cnf -uroot shutdown"
done

#### clear cgroup ####
echo_blue "\n\n#### clear cgconfig ####"
/u01/cgroup/cgroup_clear.sh
lscgroup
sed -i s:innodb_buffer_pool_size=17G:innodb_buffer_pool_size=35G:g /u01/mysql/my.cnf
sed -i s:innodb_buffer_pool_size=18G:innodb_buffer_pool_size=35G:g /u01/mysql/my.cnf

#### start mysql ####
echo_blue "\n\n#### start mysql ####"
## stop mysql 1 ##
echo_blue "## start mysql 1 ##"
su - mysql -c "export LANG=c; (/u01/mysql/bin/mysqld_unsafe   --defaults-file=/u01/mysql/my.cnf  --user=mysql >/dev/null 2>&1 &)"

#### check cgroup ####
echo_blue "\n\n#### check cgroup ####"
service  cgconfig status

echo_red "\n\n#### change buffer pool to 35G if needed ####"

#### start dbagent ####
dbagent offline `hostname`:3406

#### start dbagent ####
dbagent enable


exit 0